package galaxies.starRegions;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;

import com.jme3.math.Vector2f;


/*
 * Builds core star regions
 * 
 * Inputs:  Dimensions of a full, triangular section of a spiral galaxy core.  Number of arms in the galaxy.
 * 		Number of stars in the total arm
 * Outputs:  ArrayList of MArmStarRegions, each of which is a sub-segment of the arm, containing:
 * 		1) Dimensions of the region
 * 		2) Number of star locations in the region
 * 		3) Location and rotation of the region
 * 		4) Area of the region (LY^2)
 * 
 * Star regions are used by a galaxy factory to generate stars within their boundaries.
 * 
 * NOTE:  Does not output list of Controllers--MCoreStarRegions are directly required by calling FMSpiralGalaxyClass
 */
public class StarRegionSpiralCoreModelBuilder {
	
	
	public ArrayList<StarRegionSpiralCoreModel> createCoreStarRegions(double tSide, int numSteps) {
		ArrayList<StarRegionSpiralCoreModel> regions = new ArrayList<StarRegionSpiralCoreModel>();
		
		double thetaStep;
		double theta;
		Vector2f vec1, vec2, vec0;
		
		thetaStep = 2*Math.PI/numSteps;
		
		LinkedHashMap<Integer, Vector2f> initPoints = new LinkedHashMap<Integer, Vector2f>();		
		
		for (int i = 0; i < numSteps; i++) {
			theta = thetaStep*(i+1);
			
			//Leading triangle side vector
			vec2 = new Vector2f((float) (tSide*Math.cos(theta)), (float) (tSide*Math.sin(theta)));
			//Trailing triangle side vector
			vec1 = new Vector2f((float) (tSide*Math.cos(theta-thetaStep)), (float) (tSide*Math.sin(theta-thetaStep)));
			//Vector to origin
			vec0 = new Vector2f(0.0f, 0.0f);
			
			initPoints.put(0, vec0);
			initPoints.put(1, vec1);
			initPoints.put(2, vec2);
			
			StarRegionSpiralCoreModel region = new StarRegionSpiralCoreModel(initPoints);
			region.setLocation(vec0);
			region.setRotation(theta);						
			regions.add(region);
			
			initPoints.clear();
		}
		
		return regions;
	}
	

}
